package com.crm.controller.system;


import com.crm.dto.QueryDictTypeDto;
import com.crm.pojo.Dict;
import com.crm.result.ResponseResult;
import com.crm.service.system.DictTypeService;
import com.github.pagehelper.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Xanny
 */
@RestController
@RequestMapping("/system/dict/type")
@RequiredArgsConstructor
public class DictTypeController {

    private final DictTypeService dictTypeService;


    /**
     * 完成字典dictType的查询
     *
     * @return
     */
    @GetMapping("/list")
    public ResponseResult searchList(QueryDictTypeDto dto) {
        Page<Dict> page = dictTypeService.queryAll(dto);
        return ResponseResult.success().put("rows", page.getResult())
                .put("total", page.getTotal());
    }

    /**
     * 新增字典数据
     *
     * @param dict
     * @return
     */
    @PostMapping
    public ResponseResult saveDictData(@RequestBody Dict dict) {
        dictTypeService.save(dict);
        return ResponseResult.success();
    }

    /**
     * 根据dict_Id查询dict_type
     *
     * @param id
     */
    @GetMapping("{id}")
    public ResponseResult getById(@PathVariable Integer id) {
        Dict dict = dictTypeService.getById(id);
        return ResponseResult.success(dict);
    }

    /**
     * 修改
     */
   @PutMapping
    public ResponseResult update(@RequestBody Dict dict) {
        dictTypeService.update(dict);
        return ResponseResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{ids}")
    public ResponseResult delete(@PathVariable("ids") List<Integer> ids){
        dictTypeService.delete(ids);
        return ResponseResult.success();
    }
}
